<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
        <meta name="apple-mobile-web-app-capable" content="yes" />

        <!-- Base Css Files -->
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/jqueryui/ui-lightness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/fontello/css/fontello.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/animate-css/animate.min.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/css/component.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/magnific-popup/magnific-popup.css" rel="stylesheet" /> 
        <link href="__PUBLIC__/statics/coco-chat/assets/css/style.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/statics/coco-chat/assets/css/style-responsive.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/pace/pace.css" rel="stylesheet" />
        <link href="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/styles/metro/notify-metro.css" rel="stylesheet" type="text/css" />
        
        <!-- Extra CSS Files -->
      	<link href="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-validator/css/bootstrapValidator.min.css" rel="stylesheet"/>
      	
        <!-- Custom Css Files -->
        <link href="__ADMIN_CSS__/style.css"  rel="stylesheet" />
    </head>
    <body>
	<!-- Begin page -->
	<div>
		<div class="sub-header-title">
			<h2>修改密码</h2>
		</div>
		<form role="form" id="password-form" class="form-horizontal" action="{:U('Admin/editPassword')}">
			<div class="form-group">
				<label for="old_password" class="col-sm-2 control-label"><span class="red_star">*</span>旧密码</label>
				<div class="col-sm-5">
				  	<input type="password" class="form-control" id="old_password" name="old_password" value="">
				</div>
				<div class="col-sm-5">
					<p class="help-block">必须在6~20个字符之间</p>
				</div>
			</div>
			<div class="form-group">
				<label for="password" class="col-sm-2 control-label"><span class="red_star">*</span>新密码</label>
				<div class="col-sm-5">
				  	<input type="password" class="form-control" id="password" name="password" value="">
				</div>
				<div class="col-sm-5">
					<p class="help-block">必须在6~20个字符之间(必须与确认密码一致)</p>
				</div>
			</div>
			<div class="form-group">
				<label for="repassword" class="col-sm-2 control-label"><span class="red_star">*</span>确认密码</label>
				<div class="col-sm-5">
				  	<input type="password" class="form-control" id="repassword" name="re_password" value="">
				</div>
				<div class="col-sm-5">
					<p class="help-block">必须在6~20个字符之间(必须与新密码一致)</p>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-4 col-sm-4">
                    <button type="submit" class="btn btn-success">保存</button>
                </div>
			</div>
		</form>
	</div>
	<!-- End of page -->
	
	<!-- Base Js Files -->
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery/jquery-1.11.1.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap/js/bootstrap.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jqueryui/jquery-ui-1.10.4.custom.min.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-ui-touch/jquery.ui.touch-punch.min.js"></script>
 	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-detectmobile/detect.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/fastclick/fastclick.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-slimscroll/jquery.slimscroll.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/js/classie.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/nifty-modal/js/modalEffects.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/notify.min.js"></script>
    <script src="__PUBLIC__/statics/coco-chat/assets/libs/jquery-notifyjs/styles/metro/notify-metro-blue.js"></script>
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/pace/pace.min.js"></script>
	
	<!-- Extra Js Files -->
	<script src="__PUBLIC__/statics/coco-chat/assets/libs/bootstrap-validator/js/bootstrapValidator.min.js"></script>
	
	<!-- Custom Js Files -->
	<script src="__PUBLIC_JS__/sha1.js"></script>
	<script src="__ADMIN_JS__/common.js"></script>
	
	<script>
	$(function(){
		$('#password-form').bootstrapValidator({
	        message: '',
	        trigger: 'blur',
	        submitHandler: function(validator, form, submitButton) {
		      	//询问框
				window.parent.layer.confirm('确认修改密码吗？', {
					btn: ['确认','取消'], //按钮
					cancel: function(index){ 
				    	window.parent.layer.close(index);
						$('#password-form').bootstrapValidator('disableSubmitButtons', false);
					}
				}, function(index){
					var f_data = $('form').serializeArray();
					var data = {};
					$.each(f_data, function(i, field){
						if(field.name=='old_password' || field.name=='password' || field.name=='re_password') {
							data[field.name] = hex_sha1(field.value);
						} else {
							data[field.name] = field.value;
						}
				  	});
					// 用ajax提交表单
			      	$.post(form.attr('action'), data, function(response) {
			      		//弹出提示
						window.parent.layer.msg(response.message);
			      		
			      		//根据请求相应状态提示通知
			       		if(response.status){
			       			notify("success",response.message);
							$(form)[0].reset();
							$(form).data('bootstrapValidator').resetForm();
							window.location.reload();
						}else{
							notify("error",response.message);
						}
			        }, 'json');
			      	window.parent.layer.close(index);
				}, function(index){
					window.parent.layer.close(index);
					$('#password-form').bootstrapValidator('disableSubmitButtons', false);
				});
	        },
	        fields: {
	        	old_password: {
	                validators: {
	                	notEmpty: {
	                    },
	                    stringLength: {
	                        min: 6,
	                        max: 20,
	                    },
	                }
	            },
	            password: {
	                validators: {
	                	notEmpty: {
	                    },
	                    stringLength: {
	                        min: 6,
	                        max: 20,
	                    },
	                    callback: {
	    					callback:function(value, validator){
	    						var re_password = $('#password-form').find("input[name=re_password]").val();
	    						if (re_password == '' || value != re_password) {
	    							$('#password-form').data('bootstrapValidator').updateElementStatus($('#password-form').find("input[name='re_password']"), "INVALID", null );
	    						} else {
	    							$('#password-form').data('bootstrapValidator').updateElementStatus($('#password-form').find("input[name='re_password']"), "VALID", null );
	    						}
	    						return true;
	    					}
	    				}
	                }
	            },
	            re_password: {
	                validators: {
	                	notEmpty: {
	                    },
	                    stringLength: {
	                        min: 6,
	                        max: 20,
	                    },
	                    identical: {
	                        field: 'password',
	                    }
	                }
	            }
	        }
	    });
	});
	</script>
	</body>
</html>